package com.example.mypc.fragmentdemo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

/**
 * Created by MyPC on 2016/10/11.
 *
 */
public class MenuFragment extends Fragment implements View.OnClickListener{
    /*fragment 离不开actviity 依附actiity存在
    * 可以保证在其他的activity里也可以使用到;
    * */

    //当创建视图的时候;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.menu_58_fragment_layout,container,false);
    }

    //当视图被创建的时候;

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Button bt1 = (Button) view.findViewById(R.id.bt_1);
        Button bt2 = (Button) view.findViewById(R.id.bt_2);
        Button bt3 = (Button) view.findViewById(R.id.bt_3);
        Button bt4 = (Button) view.findViewById(R.id.bt_4);
        bt1.setOnClickListener(this);
        bt2.setOnClickListener(this);
        bt3.setOnClickListener(this);
        bt4.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Toast.makeText(getContext(),"fragment-->第"+v.getTag()+"个",Toast.LENGTH_LONG).show();
    }

}
